// 首页-搜索

const router = require('express').Router()
const db = require('../../../dbconfig')

router.post('/indexSearch',(req,res) => {
    let result = req.query.searchValue
    let sql = "SELECT id,name FROM artisticworks WHERE name LIKE '%" + result + "%' or painter LIKE '%" + result + "%' or country LIKE '%" + result + "%' or country LIKE '%" + result + "%'" // sql语句
    // console.log(sql);
    db.query(sql, (err, data) => {
        if(err){
            res.send({code: 400,message: '服务器无响应'})
        }if(data.length === 0){
            // res.send({code: 200, })
            res.send({code: 404,message: '查询为空'})
            console.log('查询为空');
        }else(
            res.send({code: 200, data})
        )
    })
})

module.exports = router